package com.enjoyor.soa.traffic.rest.tsms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tsms.AssessItemsDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.IAssessItemsConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth
@RestController
@RequestMapping({ "/assessItems" }) // getCommonPlacePage
@Api("AssessItemsController相关api")
@CrossOrigin
public class AssessItemsController {

	@Autowired
	IAssessItemsConsumeService iAssessItemsConsumeService;

	/**
	 * 考核项分页
	 * 
	 * @param page
	 * @return zyh
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@GetMapping(value = { "/getAssessItemsPage" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("考核项分页")
	public ResultPojo getAssessItemsPage(Page page, HttpServletRequest request) {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo = iAssessItemsConsumeService.getAssessItemsPage(page);
		return resultPojo;
	}

	/**
	 * 获取考核List；
	 * @return zyh
	 */
	@GetMapping(value = { "/getAssessItemsList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = AssessItemsDto.class, code = 0, message = "")
	@ApiOperation("查询考核List")
	public ResultPojo getAssessItemsList(HttpServletRequest request) {
		return iAssessItemsConsumeService.getAssessItemsList();
	}

	/**
	 * @param AssessItemsDto
	 * @return
	 */
	@PostMapping(value = { "/addAssessItems" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加考核项")
	public ResultPojo addAssessItems(@RequestBody AssessItemsDto assessItemsDto, HttpServletRequest request) {
		return iAssessItemsConsumeService.addAssessItems(assessItemsDto,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}

	@PutMapping(value = { "/editAssessItems" }, consumes = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改考核项")
	public ResultPojo editAssessItems(@RequestBody AssessItemsDto assessItemsDto, HttpServletRequest request) {
		return iAssessItemsConsumeService.editAssessItems(assessItemsDto,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}

	@DeleteMapping(value = { "/delAssessItems" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("删除考核项信息")
	@ApiImplicitParam(name = "itemsId", value = "考核项编号", paramType = "query", required = true, dataType = "String")
	public ResultPojo delCommonPlace(
			@RequestParam(defaultValue = "",value="itemsId", required=true) String itemsId, 
			HttpServletRequest request) {
		return iAssessItemsConsumeService.deleteAssessItems(itemsId,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}

}
